import {createRouter,createWebHashHistory,RouteRecordRaw} from "vue-router"
import { get } from "../utils/session"
import settingRoutes from "./settings"
import contymentRoutes from "./countyment"
const routes:RouteRecordRaw[]=[// RouteRecordRaw 约束
    {
       path:'/',
       redirect:"/login"
    },
    {
        name:'login',
        path:'/login',
        component:()=>import("../views/Login.vue")
    },
    {
        name:'layout',
        path:'/layout',
        component:()=>import("../views/Layout.vue"),
        children:[
           ...settingRoutes,
           ...contymentRoutes
        ]
    },
]
const router=createRouter({
    history:createWebHashHistory(),
    routes
})
router.beforeEach((to,from,next)=>{
    if(to.path=="/login"){
        next()
    }else{
        let token=get("token")
        if(token){
            next()
        }else{
            next("/login")
        }
    }
})
export default router